<%@ include file="/WEB-INF/template/include.jsp" %>

<openmrs:require privilege="Add/Edit Lab" otherwise="/login.htm" redirect="/module/simplelabentry/resultEntry.htm" />

<%@ include file="/WEB-INF/template/header.jsp" %>

<openmrs:htmlInclude file="/scripts/dojo/dojo.js" />
<openmrs:htmlInclude file="/dwr/interface/DWRConceptService.js" />
<openmrs:htmlInclude file="/moduleResources/simplelabentry/lab.js" />

<h2><spring:message code="simplelabentry.lab.manage"/></h2>

<script>
	function  submitForm(){
		var invest = document.getElementById("investigationNames");
		for( var i=0; i< invest.childNodes.length; i++ )
		{
			invest.childNodes[i].selected=true;
		}
		var confidential = document.getElementById("confidentialTestNames");
		for( var i=0; i< confidential.childNodes.length; i++ )
		{
			confidential.childNodes[i].selected=true;
		}
		document.forms["labForm"].submit();
	}
</script>

<c:forEach items="${errors.allErrors}" var="error">
	<span class="error"><spring:message code="${error.defaultMessage}" text="${error.defaultMessage}"/></span>
</c:forEach>
<spring:bind path="lab">
<c:if test="${not empty  status.errorMessages}">
<div class="error">
<ul>
<c:forEach items="${status.errorMessages}" var="error">
    <li>${error}</li>   
</c:forEach>
</ul>
</div>
</c:if>
</spring:bind>
<form method="post" class="box" id="labForm" onsubmit="return false;">
<table>
	<tr>
		<td><spring:message code="general.name"/></td>
		<td>
			<spring:bind path="lab.name">
				<input type="text" tabindex="1"  name="${status.expression}" value="${status.value}" size="35" />
				<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="billing.description"/></td>
		<td>
			<spring:bind path="lab.description">
				<input type="text" tabindex="2"  name="${status.expression}" value="${status.value}" size="35" />
				<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="simplelabentry.lab.role"/></td>
		<td>
			<spring:bind path="lab.role">
			<select name="${status.expression}" tabindex="3" >
				<option value=""><spring:message code="hospitalcore.pleaseSelect"/></option>
                <c:forEach items="${roles}" var="role">
                    <option value="${role.role}" <c:if test="${role.role == lab.role.role}">selected</c:if> >${role.role}</option>
                </c:forEach>
   			</select>
			<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="simplelabentry.lab.orderType"/></td>
		<td>
			<spring:bind path="lab.labOrderType">
			<select name="${status.expression}"  tabindex="4" >
				<option value=""><spring:message code="hospitalcore.pleaseSelect"/></option>
                <c:forEach items="${orderTypes}" var="orderType">
                    <option value="${orderType.orderTypeId}" <c:if test="${orderType.orderTypeId == lab.labOrderType.orderTypeId}">selected</c:if> >${orderType.name}</option>
                </c:forEach>
   			</select>
			<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="simplelabentry.lab.labTestEncounterType"/></td>
		<td>
			<spring:bind path="lab.labTestEncounterType">
			<select name="${status.expression}" tabindex="5" >
				<option value=""><spring:message code="hospitalcore.pleaseSelect"/></option>
                <c:forEach items="${labEncounterTypes}" var="encounterType">
                    <option value="${encounterType.encounterTypeId}" <c:if test="${encounterType.encounterTypeId == lab.labTestEncounterType.encounterTypeId}">selected</c:if> >${encounterType.name}</option>
                </c:forEach>
   			</select>
			<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="simplelabentry.lab.patientIdentifierType"/></td>
		<td>
			<spring:bind path="lab.patientIdentifierType">
			<select name="patientIdentifierType"  tabindex="6" >
				<option value=""><spring:message code="hospitalcore.pleaseSelect"/></option>
                <c:forEach items="${patientIdentifierTypes}" var="patientIdentifierType">
                    <option value="${patientIdentifierType.patientIdentifierTypeId}" <c:if test="${patientIdentifierType.patientIdentifierTypeId == lab.patientIdentifierType.patientIdentifierTypeId}">selected</c:if> >${patientIdentifierType.name}</option>
                </c:forEach>
   			</select>
			<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr >
		<th valign="top"><spring:message code="simplelabentry.lab.investigationsToDisplay"/></th>
		<td>

				<!-- <input type="hidden" name="${status.expression}" id="investigationIds" size="40" value='<c:forEach items="${lab.investigationsToDisplay}" var="item">${item.conceptId} </c:forEach>' />
			 -->
			
			<table cellspacing="0" cellpadding="0">
				<tr>
					<td valign="top">
						<spring:bind path="lab.investigationsToDisplay">
							<select class="largeWidth" size="6" name="${status.expression}" id="investigationNames" multiple="multiple" onKeyUp="listKeyPress('investigationNames',  ' ', event)">
								<c:forEach items="${lab.investigationsToDisplay}" var="item">
									<option value="${item.conceptId}">${item.name} (${fn:substring(item.conceptId, 0, fn:indexOf(item.conceptId, '^'))})</option>
								</c:forEach>
							</select>
							<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
						</spring:bind>
					</td>
					<td valign="top" class="buttons">
						<span dojoType="ConceptSearch" widgetId="aSearch" includeDrugConcepts="false"></span><span dojoType="OpenmrsPopup" searchWidget="aSearch" searchTitle='<spring:message code="Concept.find"/>' changeButtonValue='<spring:message code="general.add"/>' showConceptIds="true" showIfHiding="true"></span>
						<input type="button" value="<spring:message code="general.remove"/>" class="smallButton" onClick="removeItem('investigationNames',  ' ');"/><br/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr >
		<th valign="top"><spring:message code="simplelabentry.lab.confidentialTestsToDisplay"/></th>
		<td>
			
				<!-- <input type="hidden" name="${status.expression}" id="confidentialTestIds" size="40" value='<c:forEach items="${lab.confidentialTestsToDisplay}" var="item">${item.conceptId} </c:forEach>' />
				 -->
			
			<table cellspacing="0" cellpadding="0">
				<tr>
					<td valign="top">
					<spring:bind path="lab.confidentialTestsToDisplay">
						<select class="largeWidth" size="6" name="${status.expression}" id="confidentialTestNames" multiple="multiple" onKeyUp="listKeyPress('confidentialTestNames',  ' ', event)">
							<c:forEach items="${lab.confidentialTestsToDisplay}" var="item">
								<option value="${item.conceptId}">${item.name} (${fn:substring(item.conceptId, 0, fn:indexOf(item.conceptId, '^'))})</option>
							</c:forEach>
						</select>
						<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
						</spring:bind>
					</td>
					<td valign="top" class="buttons">
						<span dojoType="ConceptSearch" widgetId="cSearch" includeDrugConcepts="false"></span><span dojoType="OpenmrsPopup" searchWidget="cSearch" searchTitle='<spring:message code="Concept.find"/>' changeButtonValue='<spring:message code="general.add"/>' showConceptIds="true" showIfHiding="true"></span>
						<input type="button" value="<spring:message code="general.remove"/>" class="smallButton" onClick="removeItem('confidentialTestNames',  ' ');"/><br/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td valign="top"><spring:message code="simplelabentry.lab.rescheduleperiod"/></td>
		<td>
			<spring:bind path="lab.rescheduleperiod">
				<input type="text"  name="${status.expression}" value="${status.value}" size="35" />
				<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
	<tr>
		<td><spring:message code="general.retired" /></td>
		<td>
			<spring:bind path="lab.retired">
				<openmrs:fieldGen type="java.lang.Boolean" formFieldName="${status.expression}" val="${status.editor.value}" parameters="isNullable=false" />
				<c:if test="${status.errorMessage != ''}"><span class="error">${status.errorMessage}</span></c:if>
			</spring:bind>
		</td>
	</tr>
</table>
<br />
<input type="button" onclick="submitForm()" value="<spring:message code="general.save"/>">
<input type="button" value="<spring:message code="general.cancel"/>" onclick="javascript:window.location.href='lab.list'">
</form>
<%@ include file="/WEB-INF/template/footer.jsp" %>